//
// Created by Administrator on 2023/5/28.
//


#include "../header/LDF_Widget.h"


LDF_Widget::LDF_Widget():
        we(new Widget_Event(this)), client(new Client(this)), c_b(new Close_Button(this)), max_b(new Max_Button(this)), mini_b(new Mini_Button(this))
{
    this->Profile();
}


LDF_Widget::~LDF_Widget()
{
    delete we, client, c_b, max_b, mini_b;
}


void LDF_Widget::Profile()
{
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setAttribute(Qt::WA_DeleteOnClose, true);
    this->resize(this->width, this->height);
    this->move((DESKTOP_WIDTH - this->width) / 2, (DESKTOP_HEIGHT - this->height) / 2);


    this->setMinimumSize(this->width, this->height);
    this->setMaximumSize(DESKTOP_WIDTH, DESKTOP_HEIGHT - 40);


    this->setMouseTracking(true);



}


QPoint LDF_Widget::Size()
{
    QPoint size(this->width, this->height);
    return size;
}


Client<LDF_Widget> *LDF_Widget::Get_Client()
{
    return this->client;
}


void LDF_Widget::Set_Color(int r, int g, int b, int a)
{
    QPainter main_widget_painter(this);
    main_widget_painter.setBrush(QColor::fromRgb(r, g, b, a));
}


void LDF_Widget::Widget_Mini()
{
    this->showMinimized();
}


void LDF_Widget::mouseMoveEvent(QMouseEvent* event)
{
    this->we->mouseMoveEvent(event);
}


void LDF_Widget::mousePressEvent(QMouseEvent* event)
{
    this->we->mousePressEvent(event);
}


void LDF_Widget::mouseReleaseEvent(QMouseEvent* event)
{
    this->we->mouseReleaseEvent(event);
}


void LDF_Widget::paintEvent(QPaintEvent *event)
{
    QPainter main_widget_painter(this);
    main_widget_painter.setRenderHint(QPainter::Antialiasing);
    main_widget_painter.setBrush(QColor::fromRgb(10, 10, 10, 255));

    QRect rect = this->rect();
    main_widget_painter.drawRoundedRect(rect,10,10);

}


void LDF_Widget::resizeEvent(QResizeEvent* event)
{
    this->client->Redraw();
    this->c_b->Redraw();
    this->max_b->Redraw();
    this->mini_b->Redraw();
}